import { Coordinate } from '../model/coordinate';

import { shapeSize } from './series-markers-utils';

export function drawCircle(
	ctx: CanvasRenderingContext2D,
	centerX: Coordinate,
	centerY: Coordinate,
	size: number
): void {
	const circleSize = shapeSize('circle', size);
	const halfSize = (circleSize - 1) / 2;

	ctx.beginPath();
	ctx.arc(centerX, centerY, halfSize, 0, 2 * Math.PI, false);

	ctx.fill();
}

export function drawCircleFire(
	ctx: CanvasRenderingContext2D,
	centerX: Coordinate,
	centerY: Coordinate,
	size: number,
	drawIdx:number
): void {
	const circleSize = shapeSize('circle', size);
	const halfSize = (circleSize - 1) / 2;

	ctx.beginPath();
	ctx.arc(centerX, centerY, halfSize, 0, 2 * Math.PI, false);
	ctx.fill();
	ctx.closePath()

	let min = 0.7
	let dex = min+(drawIdx%45)/5
	let Radis = halfSize + dex*dex / 13
	let num = 40
	var f = halfSize / Radis;
    ctx.fillStyle  = "rgba(255,255,255,"+f+")";
	ctx.globalCompositeOperation = 'lighter';
	for(let i=0;i<num;i+=2){
        // ctx.globalAlpha = f;
		ctx.beginPath();
		let arc = 2*i * Math.PI/num;
		let sin = Radis*Math.sin(arc)
		let cos = Radis*Math.cos(arc)
		let x = centerX + sin;
		let y = centerY + cos;
		ctx.arc(x, y, 0.5, 0, Math.PI*2);
		ctx.fill()
	}
}

export function hitTestCircle(
	centerX: Coordinate,
	centerY: Coordinate,
	size: number,
	x: Coordinate,
	y: Coordinate
): boolean {
	const circleSize = shapeSize('circle', size);
	const tolerance = 2 + circleSize / 2;

	const xOffset = centerX - x;
	const yOffset = centerY - y;

	const dist = Math.sqrt(xOffset * xOffset + yOffset * yOffset);

	return dist <= tolerance;
}
